package com.cn.bulu.TEST;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.fastjson.JSONObject;
import com.cn.bulu.service.impl.CustomerServiceImpl;
import com.cn.bulu.utils.AESCipher;
import com.cn.bulu.utils.Constant;

import cn.jiguang.common.ClientConfig;
import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jpush.api.JPushClient;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.Notification;

public class Test1 {
	
	public static void main(String[] args) {
		//System.out.println(new Integer(1)==1);
		Map<String,Object> account = new HashMap<>();
		account.put("phone", "18503800931");
		account.put("password", "qqqqqq");
		System.err.println(System.currentTimeMillis());
		try {
			System.out.println(JSONObject.toJSONString(account));
			System.err.println(AESCipher.aesEncryptString(JSONObject.toJSONString(account), Constant.ENCRYPTKEY));
			System.err.println(AESCipher.aesDecryptString("fi6AWhNqXXUCPg4NQccS1XT32EU+HryPuHcsWjLNKHLTchiC6UHggRdeXE/7vnkY", Constant.ENCRYPTKEY));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private Logger  logger= Logger.getLogger(Test1.class);
	
	@Test
	public void test1(){
		 JPushClient jpushClient = new JPushClient(Constant.MASTER_SECRET_MERCHANTS, Constant.APP_KEY_MERCHANTS, null, ClientConfig.getInstance());

		    // For push, all you need do is to build PushPayload object.
		    PushPayload payload = buildPushObject_android_tag_alertWithTitle();

		    try {
		        PushResult result = jpushClient.sendPush(payload);
		        logger.info("Got result - " + result);

		    } catch (APIConnectionException e) {
		        // Connection error, should retry later
		    	logger.error("Connection error, should retry later", e);

		    } catch (APIRequestException e) {
		        // Should review the error, and fix the request
		    	logger.error("Should review the error, and fix the request", e);
		    	logger.info("HTTP Status: " + e.getStatus());
		    	logger.info("Error Code: " + e.getErrorCode());
		    	logger.info("Error Message: " + e.getErrorMessage());
		    }
	}
	
	
	 public static PushPayload buildPushObject_android_tag_alertWithTitle() {
		 return PushPayload.newBuilder()
	                .setPlatform(Platform.all())
	                .setAudience(Audience.alias("863549038499622"))
	                .setNotification(Notification.alert("进行分发"))
	                .build();
    }
}
